Crate celery

source ·
Expand description

A Rust implementation of Celery for producing and consuming asynchronous tasks with a distributed message queue.

Examples

Define tasks by decorating functions with the task attribute:

use celery::prelude::*;

#[celery::task]
fn add(x: i32, y: i32) -> TaskResult<i32> {
    Ok(x + y)
}

Then create a Celery app with the app! macro and register your tasks with it:

let my_app = celery::app!(
    broker = AMQPBroker { std::env::var("AMQP_ADDR").unwrap() },
    tasks = [add],
    task_routes = [],
).await?;

The Celery app can be used as either a producer or consumer (worker). To send tasks to a queue for a worker to consume, use the Celery::send_task method:

my_app.send_task(add::new(1, 2)).await?;

And to act as a worker to consume tasks sent to a queue by a producer, use the Celery::consume method:

my_app.consume().await?;

Modules

Celery Beat is an app that can automatically produce tasks at scheduled times.
The broker is an integral part of a Celery app. It provides the transport for messages that encode tasks.
All error types used throughout the library.
A “prelude” for users of the celery crate.
Defines the Celery protocol.
Provides the Task trait as well as options for configuring tasks.

Macros

A macro for creating a Celery app.
A macro for creating a Beat app.

Structs

A Celery app is used to produce or consume tasks asynchronously. This is the struct that is created with the app! macro.
Used to create a Celery app with a custom configuration.

Attribute Macros

A procedural macro for generating a Task from a function.